package node.utils;

public class RouterUtil {
    public static final byte DCF = 0X0A;
    public static final byte FS = 0X0B;
    public static final byte BGD = 0X0C;
    public static byte[] sendorder = new byte[21];

    static {
        sendorder[0] = (byte) 0xFD;
        sendorder[1] = 0x0F;
        sendorder[2] = 0x0A;
        sendorder[3] = (byte) 0xFF;
        sendorder[7] = 0x0A;
        sendorder[8] = (byte) 0xFF;
        sendorder[9] = (byte) 0xDD;
        sendorder[10] = 0x01;
    }

    private byte[] addr = new byte[2];
    private byte[] macaddr = new byte[8];

    public byte[] getAddr() {
        return addr;
    }

    public void setAddr(byte[] addr) {
        this.addr = addr;
        sendorder[2] = addr[0];
        sendorder[3] = addr[1];
        sendorder[7] = addr[0];
        sendorder[8] = addr[1];
    }

    public byte[] getMacaddr() {
        return macaddr;
    }

    public void setMacaddr(byte[] macaddr) {
        this.macaddr = macaddr;
        sendorder[13] = macaddr[0];
        sendorder[14] = macaddr[1];
        sendorder[15] = macaddr[2];
        sendorder[16] = macaddr[3];
        sendorder[17] = macaddr[4];
        sendorder[18] = macaddr[5];
        sendorder[19] = macaddr[6];
        sendorder[20] = macaddr[7];
    }

    public byte[] RelayOpen() {
        sendorder[6] = 'K';
        sendorder[9] = (byte) 0xDD;
        sendorder[10] = (byte) 0x01;
        sendorder[11] = (byte) 0xAA;
        return sendorder;
    }

    public byte[] RelayClear(){
        sendorder[6]='K';
        sendorder[9] = (byte) 0xDD;
        sendorder[10] = (byte) 0x01;
        sendorder[11] = (byte) 0xBB;
        return sendorder;
    }

    public byte[] MultDcfOpen(byte type){
        sendorder[6]=0x09;
        sendorder[9] = (byte) 0xDD;
        sendorder[10]= type;
        sendorder[11] = (byte) 0xBB;
        return sendorder;
    }

    public byte[] MultDcfClear(byte type){
        sendorder[6]=0x09;
        sendorder[9] = (byte) 0xDD;
        sendorder[10]= type;
        sendorder[11] = (byte) 0xBB;
        return sendorder;
    }

    public byte[] MultSmg(byte num){
        sendorder[6]=0x09;
        sendorder[9] = (byte) 0xEA;
        sendorder[10]= num;
        sendorder[11] = (byte) 0xAA;
        return sendorder;
    }

    public byte[] MultDj(byte direction , byte speed){
        sendorder[6]=0x09;
        sendorder[9] = (byte) 0xEB;
        sendorder[10]= direction;
        sendorder[11] = speed;
        return sendorder;
    }

}
